package com.tudouji.project.d3.service.impl;

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.tudouji.common.utils.DateUtils;
import com.tudouji.common.utils.SecurityUtils;
import com.tudouji.common.utils.StringUtils;
import com.tudouji.project.customer.domain.Customer;
import com.tudouji.project.customer.mapper.CustomerMapper;
import com.tudouji.project.system.domain.SysDept;
import com.tudouji.project.system.domain.SysUser;
import com.tudouji.project.system.mapper.SysDeptMapper;
import com.tudouji.project.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tudouji.project.d3.mapper.D3ShopMapper;
import com.tudouji.project.d3.domain.D3Shop;
import com.tudouji.project.d3.service.ID3ShopService;

/**
 * D3平台店铺Service业务层处理
 * 
 * @author tudouji
 * @date 2023-03-29
 */
@Service
public class D3ShopServiceImpl implements ID3ShopService 
{
    @Autowired
    private D3ShopMapper d3ShopMapper;
    @Autowired
    private SysUserMapper sysUserMapper;
    @Autowired
    private CustomerMapper customerMapper;
    @Autowired
    private SysDeptMapper sysDeptMapper;


    /**
     * 查询D3平台店铺
     * 
     * @param id D3平台店铺ID
     * @return D3平台店铺
     */
    @Override
    public D3Shop selectD3ShopById(Long id)
    {
        return d3ShopMapper.selectD3ShopById(id);
    }

    /**
     * 查询D3平台店铺列表
     * 
     * @param d3Shop D3平台店铺
     * @return D3平台店铺
     */
    @Override
    public List<D3Shop> selectD3ShopList(D3Shop d3Shop)
    {
        return d3ShopMapper.selectD3ShopList(d3Shop);
    }

    /**
     * 新增D3平台店铺
     * 
     * @param d3Shop D3平台店铺
     * @return 结果
     */
    @Override
    public int insertD3Shop(D3Shop d3Shop)
    {
        d3Shop.setCreateTime(DateUtils.getNowDate());
        return d3ShopMapper.insertD3Shop(d3Shop);
    }

    /**
     * 修改D3平台店铺
     * 
     * @param d3Shop D3平台店铺
     * @return 结果
     */
    @Override
    public int updateD3Shop(D3Shop d3Shop)
    {
        Long user= SecurityUtils.getLoginUser().getUser().getUserId();
//        String str = JSON.toJSONString(user);
        d3Shop.setUpdateTime(DateUtils.getNowDate());
        d3Shop.setUpdateby(user);
        if (StringUtils.isNotNull(d3Shop.getDeptId())){
            SysDept sysDept=sysDeptMapper.selectDeptById(d3Shop.getDeptId());
            d3Shop.setDeptName(sysDept.getDeptName());
        }
        if (StringUtils.isNotNull(d3Shop.getCustomerId())){
            Customer customer=customerMapper.selectCustomerByNewId(d3Shop.getCustomerId());
            d3Shop.setCustomerName(customer.getName());
        }
        return d3ShopMapper.updateD3Shop(d3Shop);
    }

    /**
     * 批量删除D3平台店铺
     * 
     * @param sIds 需要删除的D3平台店铺ID
     * @return 结果
     */
    @Override
    public int deleteD3ShopByIds(Long[] sIds)
    {
        return d3ShopMapper.deleteD3ShopByIds(sIds);
    }

    /**
     * 删除D3平台店铺信息
     * 
     * @param sId D3平台店铺ID
     * @return 结果
     */
    @Override
    public int deleteD3ShopById(Long sId)
    {
        return d3ShopMapper.deleteD3ShopById(sId);
    }
}
